import {loginRequest, musicRequest} from "./index"
// appid：wxf817b076af37c175
// secret：b8d78cd383a158cdd84d9dba103c0526
export function getLoginCode() {
    return new Promise((resolve, reject) => {
        wx.login({
            timeout: 1000,
            success: res => {
                const code = res.code
                resolve(code)
            },
            fail: err => {
                console.log(err)
                reject(err)
            }
        })
    })
}

export function codeToToken(code) {
    return loginRequest.post("/login", {
        code
    })
}

export function checkToken() {
    const token = wx.getStorageSync('token_key');
    return loginRequest.post("/auth", {}, {token})
}

export function postFavorRequest(id) {
    return loginRequest.post("/api/favor", {
        id
    }, true)
}

export function checkSession() {
    return new Promise((resolve) => {
        wx.checkSession({
            success: () => {
                resolve(true)
            },
            fail: () => {
                resolve(false)
            }
        })
    })
}

